
<!-- Start Forms -->
<div class="grid_7">
    <div class="box-header">Thêm Role</div>
    <div class="box">
        <form id="form" method="post" action="<?php echo $this->actionForm; ?>" enctype="multipart/form-data" name="form">
            <dl class="zend_form">
                <input type="hidden" id="itemId" name="itemId" value="<?php echo $this->itemId?>">
                <div class="row">
                    <label>Role Name:</label>
                    <input type="text" id="roleName" name="roleName"
                        value="<?php echo $this->info['roleName']?>"
                        class="required w300" minlength="3" maxlenght="255">
                </div>

                <!--Project-->
                <div class="row">
                    <label>Project:</label>
                    <ul style="width: 1000px" class="listCheckbox">
                        <fieldset>
                            <legend><input type="checkbox" onclick="$('input[name*=\'projects\']').attr('checked', this.checked);"> SELECT ALL</legend>
                        <?php foreach ($this->projects as $p) {
                                $flag = false;
                                foreach ($this->info['projects'] as $rp) {
                                    if($rp['projectId'] == $p->projectId){
                                        $flag = TRUE;
                                        break;
                                    }
                                }
                                if($flag){
                                    echo "<li><input type='checkbox' name='projects[]' checked='checked' value='" . $p->projectId . "'> {$p->projectName} </li>";
                                }else{
                                    echo "<li><input type='checkbox' name='projects[]' value='" . $p->projectId . "'> {$p->projectName} </li>";
                                }
                        }?>
                        </fieldset>
                    </ul>
                </div>

                <!--Privilege-->
                <div class="row">
                    <label>Privilege:</label>
                    <ul style="width: 1000px" class="listCheckbox">
                        <fieldset>
                            <legend><input type="checkbox" onclick="$('input[name*=\'resources\']').attr('checked', this.checked);"> SELECT ALL</legend>
                        <?php foreach ($this->resources as $r) {
                                $checked = '';
                                $privilegeId = 0;
                                $views = '';
                                foreach ($this->info['resources'] as $rr) {
                                    if($rr['resourceId'] == $r['id']){
                                        $privilegeId = $rr['privilegeId'];
                                        $views = json_decode($rr['views']);
                                        $views = (is_array($views)) ? implode('-', $views) : '';
                                        $checked = "checked='checked'";
                                        break;
                                    }
                                }
                        ?>
                            <?php if(($r['isDetail'] == 1)){?>
                            <li>
                                <input type='checkbox' name='resources[]' <?php echo $checked?> value="<?php echo $r['id'] ?>">
                                <a id="link_<?php echo $r['id'] ?>" class="viewDetail"  href="role/viewsdetail/resourceId/<?php echo $r['id'] ?>/views/<?php echo $views?>"><?php echo $r['resourceName'] ?></a>
                                <input type="hidden" id="views_<?php echo $r['id'] ?>" name="views_<?php echo $r['id'] ?>"
                                       value="<?php echo $views?>">
                            </li>
                            <?php }else{?>
                            <li>
                                <input type='checkbox' name='resources[]' <?php echo $checked?> value="<?php echo $r['id'] ?>">
                                <?php echo $r['resourceName'] ?>
                            </li>
                            <?php }?>
                        <?php }?>
                        </fieldset>
                    </ul>
                </div>


                <div class="row">
                    <label></label>
                            <input value="Submit" class="button" type="button" onclick="$('#form').submit();">

                    <a href="<?php echo $this->actionCancel?>">
                            <input value="Cancel" class="button" type="button">
                    </a>
                </div>

            </dl>
        </form>
    </div>
</div>
<!-- Start Forms -->
<!-- Start Formatting -->
<div class="grid_2">
<div class="box-header">Hướng dẫn</div>
<div class="box"><b>Hướng dẫn thêm</b><br>
<ul>

</ul>

</div>
</div>
<br class="cl" />
<!-- End Formatting -->

<script type="text/javascript" src="js/jquery.validate.js"></script>
<script>
  $(document).ready(function(){
    $("#form").validate();
  });

  //Fancy box for view Details
  $(document).ready(function(){
        $(".viewDetail").fancybox({
                    'width'				: '65%',
                    'height'			: '60%',
                    'autoScale'			: true,
                    'transitionIn'		: 'none',
                    'transitionOut'		: 'none',
                    'type'				: 'iframe'
        });
  });


</script>
